package com.cac.demo.newCode.cemop.controller;

import com.alibaba.fastjson.JSONObject;
import com.cac.demo.newCode.cemop.dto.*;
import com.cac.demo.newCode.cemop.service.CemopService;
import com.cac.demo.util.AccessLog;
import com.cac.demo.util.adapter.ResponseMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.FileNotFoundException;
import java.text.ParseException;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/Cemop")
@Api(tags = "CEMOP系统与101交互接口")
public class CemopController {

    @Resource
    CemopService cemopService;

    /**
     * CEMOP物料接收系统与WMS交互接口
     */
    @PostMapping("/getReturnOrderData")
    @AccessLog(LogType = "CEMOP系统退库单接收或驳回通知101库存", sendOrReceive = "receiveTxt")
    @ApiOperation(value = "CEMOP系统退库单接收或驳回通知101库存")
    public ResponseMsg<Object> getReturnOrderData(@RequestBody JSONObject jsonObject) {
        return cemopService.getReturnOrderData(jsonObject);
    }

    @PostMapping("/getOutboundData")
    @AccessLog(LogType = "CEMOP系统出库台账通知101库存", sendOrReceive = "receiveTxt")
    @ApiOperation(value = "CEMOP系统出库台账通知101库存")
    public ResponseMsg<Object> getOutboundData(@RequestBody JSONObject jsonObject) {
        return cemopService.getOutboundData(jsonObject);
    }

    @PostMapping("/getZeroApplicationData")
    @AccessLog(LogType = "CEMOP协调归零申请通知101库存", sendOrReceive = "receiveTxt")
    @ApiOperation(value = "CEMOP协调归零申请通知101库存")
    public ResponseMsg<Object> getZeroApplicationData(@RequestBody JSONObject jsonObject) {
        return cemopService.getZeroApplicationData(jsonObject);
    }

    @PostMapping("/getScanTransfer")
    @AccessLog(LogType = "CEMOP系统扫码移交至101库存", sendOrReceive = "receiveTxt")
    @ApiOperation(value = "CEMOP系统扫码移交至101库存")
    public ResponseMsg<Object> getScanTransfer(@RequestBody JSONObject jsonObject) {
        return cemopService.receiveMaterialDelivery(jsonObject);
    }

    @PostMapping("/sendAoSupportingLedger")
    @AccessLog(LogType = "JS_J011-101库存AO配套台账通知CEMOP系统", sendOrReceive = "sendTxt")
    @ApiOperation(value = "JS_J011-101库存AO配套台账通知CEMOP系统")
    public ResponseMsg<Object> sendAoSupportingLedger(@RequestBody CemopSupportingLedgerDTO cemopSupportingLedgerDTO) {
        return cemopService.sendAoSupportingLedger(cemopSupportingLedgerDTO);
    }

    @PostMapping("/sendCancelAoSupportingLedger")
    @AccessLog(LogType = "101库存AO取消配套台账通知CEMOP系统", sendOrReceive = "sendTxt")
    @ApiOperation(value = "101库存AO取消配套台账通知CEMOP系统")
    public ResponseMsg<Object> sendCancelAoSupportingLedger(@RequestBody CemopCancelSupportingLedgerDTO cemopSupportingLedgerDTO) {
        return cemopService.sendCancelAoSupportingLedger(cemopSupportingLedgerDTO);
    }

    @PostMapping("/sendAoMatchingOutbound")
    @AccessLog(LogType = "101库存AO配套出库通知CEMOP系统", sendOrReceive = "sendTxt")
    @ApiOperation(value = "101库存AO配套出库通知CEMOP系统")
    public ResponseMsg<Object> sendAoMatchingOutbound(@RequestBody CemopAoMatchingOutboundDTO cemopAoMatchingOutboundDTO) {
        return cemopService.sendAoMatchingOutbound(cemopAoMatchingOutboundDTO);
    }

    @PostMapping("/sendAoRevokesOutbound")
    @AccessLog(LogType = "101库存AO撤销出库通知CEMOP系统", sendOrReceive = "sendTxt")
    @ApiOperation(value = "101库存AO撤销出库通知CEMOP系统")
    public ResponseMsg<Object> sendAoRevokesOutbound(@RequestBody CemopAoRevokesOutboundDTO cemopAoRevokesOutboundDTO) {
        return cemopService.sendAoRevokesOutbound(cemopAoRevokesOutboundDTO);
    }

    @PostMapping("/sendAoSupportingTransfer")
    @AccessLog(LogType = "101库存AO配套移交通知CEMOP系统", sendOrReceive = "sendTxt")
    @ApiOperation(value = "101库存AO配套移交通知CEMOP系统")
    public ResponseMsg<Object> sendAoSupportingTransfer(@RequestBody CemopAoSupportingTransferDTO cemopAoSupportingTransferDTO) {
        return cemopService.sendAoSupportingTransfer(cemopAoSupportingTransferDTO);
    }

    @PostMapping("/getAllocateLedgerInformation")
    @AccessLog(LogType = "CEMOP系统分配台账信息通知101库存", sendOrReceive = "receiveTxt")
    @ApiOperation(value = "CEMOP系统分配台账信息通知101库存")
    public ResponseMsg<Object> getAllocateLedgerInformation(@RequestBody JSONObject jsonObject) {
        return cemopService.getAllocateLedgerInformation(jsonObject);
    }

    @PostMapping("/getLedgerOutbound")
    @AccessLog(LogType = "CEMOP系统台账出库通知101库存", sendOrReceive = "receiveTxt")
    @ApiOperation(value = "CEMOP系统台账出库通知101库存")
    public ResponseMsg<Object> getLedgerOutbound(@RequestBody JSONObject jsonObject) {
        return cemopService.getLedgerOutbound(jsonObject);
    }

    @PostMapping("/getCancelLedgerAllocation")
    @AccessLog(LogType = "CEMOP系统取消台账分配通知101库存", sendOrReceive = "receiveTxt")
    @ApiOperation(value = "CEMOP系统取消台账分配通知101库存")
    public ResponseMsg<Object> getCancelLedgerAllocation(@RequestBody JSONObject jsonObject) {
        return cemopService.getCancelLedgerAllocation(jsonObject);
    }

    @PostMapping("/getCancelLedgerOutbound")
    @AccessLog(LogType = "CEMOP系统取消台账出库通知101库存", sendOrReceive = "receiveTxt")
    @ApiOperation(value = "CEMOP系统取消台账出库通知101库存")
    public ResponseMsg<Object> getCancelLedgerOutbound(@RequestBody JSONObject jsonObject) {
        return cemopService.getCancelLedgerOutbound(jsonObject);
    }

    @PostMapping("/newCefcdEcd")
    @ApiOperation(value = "CEMOP系统接收拆分的合格证通知101库存")
    @AccessLog(LogType = "CEMOP系统接收拆分的合格证通知101库存", sendOrReceive = "receive")
    public ResponseMsg<Object> newCefcdEcd(@RequestBody JSONObject jsonObject) {
        return cemopService.newCefcdEcd(jsonObject);
    }

    @PostMapping("/getCancelDeliver")
    @AccessLog(LogType = "CEMOP与SERP系统删除交接单通知101库存", sendOrReceive = "receiveTxt")
    @ApiOperation(value = "CEMOP与SERP系统删除交接单通知101库存")
    public ResponseMsg<Object> getCancelDeliver(@RequestBody JSONObject jsonObject) {
        return cemopService.getCancelDeliver(jsonObject);
    }



    /**
     * CEMOP分拣配套系统与WMS交互接口
     */

    @PostMapping("/getReject")
    @AccessLog(LogType = "CEMOP系统工人驳回物料至101库存", sendOrReceive = "receive")
    @ApiOperation(value = "CEMOP系统工人驳回物料至101库存")
    public ResponseMsg<Object> getReject(@RequestBody JSONObject jsonObject) throws FileNotFoundException {
        return cemopService.getReject(jsonObject);
    }

    @PostMapping("/receivingMaterial")
    @AccessLog(LogType = "CEMOP系统接收物料", sendOrReceive = "receive")
    @ApiOperation(value = "CEMOP系统接收物料")
    public ResponseMsg<Object> receivingMaterial(@RequestBody JSONObject jsonObject) throws FileNotFoundException {
        return cemopService.receivingMaterial(jsonObject);
    }

    @PostMapping("/sendMatchBillInfo")
    @AccessLog(LogType = "101库存发送配套信息至装配CEMOP", sendOrReceive = "send")
    @ApiOperation(value = "101库存发送配套信息至装配CEMOP")
    public ResponseMsg<Object> sendMatchBillInfo() {
        return cemopService.sendMatchBillInfo();
    }

    @PostMapping("/sendMatchSortingInfo")
    @AccessLog(LogType = "101库存发送分拣信息至装配CEMOP", sendOrReceive = "send")
    @ApiOperation(value = "101库存发送分拣信息至装配CEMOP")
    public ResponseMsg<Object> sendMatchSortingInfo(@RequestBody String matchInfoId) {
        return cemopService.sendMatchSortingInfo(matchInfoId);
    }

    @PostMapping("/sendMaterialInfo")
    @AccessLog(LogType = "101库存配套物料信息至装配CEMOP", sendOrReceive = "send")
    @ApiOperation(value = "101库存配套物料信息至装配CEMOP")
    public ResponseMsg<Object> sendMaterialInfo(@RequestBody List<String> planIds) {
        return cemopService.sendMaterialInfo(planIds);
    }

    @PostMapping("/sendCancelDeliveryInfo")
    @AccessLog(LogType = "101库存撤销配送信息至装配", sendOrReceive = "send")
    @ApiOperation(value = "101库存撤销配送信息至装配")
    public ResponseMsg<Object> sendCancelDeliveryInfo() {
        return cemopService.sendCancelDeliveryInfo();
    }

    @PostMapping("/resSecondMatch")
    @ApiOperation(value = "装配系统工人二次配套物料至101库存")
    @AccessLog(LogType = "装配系统工人二次配套物料至101库存", sendOrReceive = "receive")
    public ResponseMsg<Object> resSecondMatch(@RequestBody JSONObject jsonObject) {
        return cemopService.receiveSecondMatch(jsonObject);
    }

    @PostMapping("/receiveMaterialDelivery")
    @ApiOperation(value = "装配系统扫码移交至101库存")
    @AccessLog(LogType = "装配系统扫码移交至101库存", sendOrReceive = "receive")
    public ResponseMsg<Object> receiveMaterialDelivery(@RequestBody JSONObject jsonObject) {
        return cemopService.receiveMaterialDelivery(jsonObject);
    }
    @PostMapping("/shopMaterialDelivery")
    @ApiOperation(value = "101扫码移交至装配")
    public ResponseMsg<Object> shopMaterialDelivery(@RequestBody List<String> toolCodes) {
        return cemopService.shopMaterialDelivery(toolCodes);
    }

    @PostMapping("/getWorkersReturnMaterials")
    @ApiOperation(value = "装配系统工人退库物料至101库存")
    @AccessLog(LogType = "装配系统工人退库物料至101库存", sendOrReceive = "receive")
    public ResponseMsg<Object> getWorkersReturnMaterials(@RequestBody JSONObject jsonObject) throws FileNotFoundException, ParseException {
        return cemopService.getWorkersReturnMaterials(jsonObject);
    }

    @PostMapping("/getRevocationTransfer")
    @ApiOperation(value = "装配系统工人撤销移交物料至101库存")
    @AccessLog(LogType = "装配系统工人撤销移交物料至101库存", sendOrReceive = "receive")
    public ResponseMsg<Object> getRevocationTransfer(@RequestBody JSONObject jsonObject) {
        return cemopService.getRevocationTransfer(jsonObject);
    }

    @PostMapping("/getChangeProcess")
    @ApiOperation(value = "工艺变更")
    @AccessLog(LogType = "工艺变更", sendOrReceive = "receive")
    public ResponseMsg<Object> getChangeProcess(@RequestBody JSONObject jsonObject) throws FileNotFoundException {
        return cemopService.getChangeProcess(jsonObject);
    }
    @PostMapping("/receiveSecondMatchAndReturn")
    @ApiOperation(value = "CEMOP系统现场正常退库与二次配套通知101库存")
    @AccessLog(LogType = "CEMOP系统现场正常退库与二次配套通知101库存", sendOrReceive = "receiveTxt")
    public ResponseMsg<Object> receiveSecondMatchAndReturn(@RequestBody JSONObject jsonObject) throws ParseException {
        return cemopService.receiveSecondMatchAndReturn(jsonObject);
    }

    /**
     *101库存确认处理通知CEMOP系统
     * @return
     */
    @PostMapping("/sendStockConfirmation")
    @AccessLog(LogType = "101库存确认处理通知CEMOP系统", sendOrReceive = "sendTxt")
    @ApiOperation(value = "101库存确认处理通知CEMOP系统")
    public ResponseMsg<Object> sendStockConfirmation(CemopStockConfirmationDTO stockConfirmationDTO) {
        return cemopService.getStockConfirmation(stockConfirmationDTO);
    }
//    @PostMapping("/sendAgreeReturnMaterials")
//    @ApiOperation(value = "101库存同意工人退库物料通知装配")
//    @AccessLog(LogType = "101库存同意工人退库物料通知装配", sendOrReceive = "send")
//    public ResponseMsg<Object> sendAgreeReturnMaterials(@RequestBody JSONObject jsonObject) throws FileNotFoundException, ParseException {
//        return cemopService.sendAgreeReturnMaterials(jsonObject);
//    }

//    @PostMapping("/sendRejectReturnMaterials")
//    @ApiOperation(value = "101库存驳回工人退库物料通知装配")
//    @AccessLog(LogType = "101库存驳回工人退库物料通知装配", sendOrReceive = "send")
//    public ResponseMsg<Object> sendRejectReturnMaterials(@RequestBody JSONObject jsonObject) {
//        return cemopService.sendRejectReturnMaterials(jsonObject);
//    }

//    @PostMapping("/sendAgreeSecondMatch")
//    @ApiOperation(value = "101库存同意物料二次配套通知装配")
//    @AccessLog(LogType = "101库存同意物料二次配套通知装配", sendOrReceive = "send")
//    public ResponseMsg<Object> sendAgreeSecondMatch(@RequestBody MsSecondMatchInfo msSecondMatchInfo) throws FileNotFoundException, ParseException {
//        return cemopService.sendAgreeSecondMatch(msSecondMatchInfo);
//    }
//
//    @PostMapping("/sendRejectSecondMatch")
//    @ApiOperation(value = "101库存驳回物料二次配套通知装配")
//    @AccessLog(LogType = "101库存驳回物料二次配套通知装配", sendOrReceive = "send")
//    public ResponseMsg<Object> sendRejectSecondMatch(@RequestBody MsSecondMatchInfo msSecondMatchInfo) {
//        return cemopService.sendRejectSecondMatch(msSecondMatchInfo);
//    }
//
    @PostMapping("/saveCemopLog")
    @ApiOperation(value = "存cemop日志")
    public ResponseMsg<Object> saveCemopLog(@RequestBody CemopLogDTO cemopLogDTO) {
        return cemopService.saveCemopLog(cemopLogDTO);
    }
    @PostMapping("/saveLocalLog")
    @ApiOperation(value = "存本地项目日志")
    public ResponseMsg<Object> saveLocalLog(@RequestBody LocalLogDTO localLogDTO) {
        return cemopService.saveLocalLog(localLogDTO);
    }
    @PostMapping("/getLogPage")
    @ApiOperation(value = "查看日志分页")
    public ResponseMsg<Object> getLogPage(@RequestBody CemopLogDTO cemopLogDTO) {
        return cemopService.getLogPage(cemopLogDTO);
    }

    /**
     *Cemop接口调用结果反馈
     * @return
     */
    @PostMapping("/sendSortBackResult")
    @AccessLog(LogType = "Cemop接口调用结果反馈", sendOrReceive = "sendTxt")
    @ApiOperation(value = "Cemop接口调用结果反馈")
    public  ResponseMsg<Object> sendSortBackResult (@RequestBody JSONObject jsonObject) {
        return cemopService.sendSortBackResult(jsonObject);
    }
    /**
     *Cemop接口调用结果反馈TXT
     * @return
     */
    @PostMapping("/getSortBackResultTxt")
    @AccessLog(LogType = "Cemop接口调用结果反馈TXT", sendOrReceive = "receiveTxt")
    @ApiOperation(value = "Cemop接口调用结果反馈TXT")
    public  ResponseMsg<Object> getSortBackResultTxt (@RequestBody JSONObject jsonObject) {
        return cemopService.getSortBackResultTxt(jsonObject);
    }
    /**
     *Cemop接口调用结果反馈Xml
     * @return
     */
    @PostMapping("/getSortBackResultXml")
    @AccessLog(LogType = "Cemop接口调用结果反馈Xml", sendOrReceive = "receive")
    @ApiOperation(value = "Cemop接口调用结果反馈Xml")
    public  ResponseMsg<Object> getSortBackResultXml (@RequestBody JSONObject jsonObject) throws FileNotFoundException {
        return cemopService.getSortBackResultXml(jsonObject);
    }
    @PostMapping("/receiveAoChange")
    @ApiOperation(value = "Cemop系统AO变更通知101")
    @AccessLog(LogType = "Cemop系统AO变更通知101", sendOrReceive = "receive")
    public ResponseMsg<Object> receiveAoChange(@RequestBody JSONObject jsonObject) {
        return cemopService.receiveAoChange(jsonObject);
    }
}
